package com.atguigu.test05.test06;

import java.util.Random;

/**
 * @author haoranlu
 * @project IntelliJ IDEA
 */
public class TestTools {
    public static void main(String[] args) {
        MyThread m1 = new MyThread();
        m1.start();

        MyThread m2 = new MyThread();
        m2.start();
    }
}
class Tools{
    public static Random rand = new Random();
    public static ThreadLocal<Integer> th = new ThreadLocal<>();
    public static void setNumber(){
        th.set(rand.nextInt(100));
    }
    public static int getNumber(){
        return th.get();
    }
}
class MyThread extends Thread{
    @Override
    public void run() {
        Tools.setNumber();
        for (int i = 0; i < 5; i++) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            int number = Tools.getNumber();
            System.out.println(Thread.currentThread().getName()+":"+number);
        }
    }
}
